﻿namespace Digitalmes.Domain.Repositories;

/// <summary>
/// 仓储对象
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IRepository<T> : ISugarRepository
    where T : class, IEntity, new()
{
    #region 查询

    /// <summary>
    /// 根据筛选条件判断是否存在数据。
    /// </summary>
    /// <param name="whereExpression">筛选条件</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据筛选条件查询数据总和。
    /// </summary>
    /// <param name="whereExpression">筛选条件</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<int> CountAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据主键 Id 查询。
    /// </summary>
    /// <param name="id">主键 Id</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<T> GetByIdAsync(dynamic id, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取所有数据。
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<List<T>> GetListAsync(CancellationToken cancellationToken = default);

    /// <summary>
    /// 根据筛选条件获取所有数据。
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, CancellationToken cancellationToken = default);

    #endregion

    #region 增、删、改

    /// <summary>
    /// 新增一条数据。
    /// </summary>
    /// <param name="insertObj">要新增的数据</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> InsertAsync(T insertObj, CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量新增数据。
    /// </summary>
    /// <param name="insertObjs">要新增的数据集合</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> InsertRangeAsync(List<T> insertObjs, CancellationToken cancellationToken = default);

    /// <summary>
    /// 更新一条数据。
    /// </summary>
    /// <param name="updateObj">要更新的数据</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> UpdateAsync(T updateObj, CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量更新数据。
    /// </summary>
    /// <param name="updateObjs">要更新的数据集合</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    Task<bool> UpdateRangeAsync(List<T> updateObjs, CancellationToken cancellationToken = default);

    #endregion
}
